clear yapdate yapdata bikdate bikdata;
s = dir('c:\manoj\geomag\data\210\yap\');
pp =1;
for i = 1:length(s)-2,
fid = fopen(['c:\manoj\geomag\data\210\bik\a5' s(i+2).name(2:7) '.bik'],'rt');
if fid ~= -1,
yapfile(pp,:) = (s(i+2).name);
bikfile(pp,:) = (['a5' s(i+2).name(2:7) '.bik']);
fclose(fid);
pp = pp+1;
end;
end;
mjd_start = datenum(2000,1,1);
for i = 1:104,
[datax] = obs_read(['c:\manoj\geomag\data\210\yap\' yapfile(i,:)],'X');
[datay] = obs_read(['c:\manoj\geomag\data\210\yap\' yapfile(i,:)],'Y');
pp = 1;
for ii = 1:24,
    for  jj = 0:59,
        yapdate(i,pp) = datenum(datax(ii,1),datax(ii,2),datax(ii,3),datax(ii,4),jj,30)-mjd_start;
        pp = pp + 1;
    end;
end;
yapdata(i,:) = sqrt(reshape(datax(:,5:64)',[1,24*60]).^2+...
    reshape(datay(:,5:64)',[1,24*60]).^2);
end;

for i = 1:104,
[datax] = obs_read(['c:\manoj\geomag\data\210\bik\' bikfile(i,:)],'X');
[datay] = obs_read(['c:\manoj\geomag\data\210\bik\' bikfile(i,:)],'Y');
pp = 1;
for ii = 1:24,
    for  jj = 0:59,
        bikdate(i,pp) = datenum(datax(ii,1),datax(ii,2),datax(ii,3),datax(ii,4),jj,30)-mjd_start;
        pp = pp + 1;
    end;
end;
bikdata(i,:) = sqrt(reshape(datax(:,5:64)',[1,24*60]).^2+...
    reshape(datay(:,5:64)',[1,24*60]).^2);
end;

%bikdata(:,1:end-6) = bikdata(:,7:end); %Seven minutes advanced due to longidunal difference of BIK and YAP
%bikdata(:,7:end) = bikdata(:,1:end-6);

L = yapdate-bikdate > 1e-3;%one data point in date matrix is wrong
yapdate(L) = bikdate(L); % 52 value in yapdate 1 row i replaced with bikdate

yapdata = yapdata*0.1;% 0.1nT is the calibration constant in the wdc file
bikdata = bikdata*0.1;

yapdh = yapdata - repmat(mean(yapdata(:,800:900),2),[1,1440]);
bikdh = bikdata - repmat(mean(bikdata(:,800:900),2),[1,1440]);
YAPMNBIK = yapdh-bikdh;
% DONOT USE THIS !!YAPMNBIK = YAPMNBIK(randperm(104),:); % This is done to
% verify the correlation (with randomized dates, it did not give much
% correlation)
yapmnbik = reshape(YAPMNBIK',[1,104*1440]);
yapdate1  = reshape(yapdate',[1,104*1440]);

%save c:\manoj\projects\eej\YAPMNBIK yapmnbik yapdate YAPMNBIK;

yapdhts = reshape(yapdh',[1,104*1440]);